package br.ucb.cesbdao.model.impl;

import java.sql.SQLException;
import java.util.ArrayList;

import lombok.Getter;
import lombok.Setter;

import org.apache.log4j.Logger;

import br.ucb.cesbdao.beans.Pessoa;
import br.ucb.cesbdao.model.AtendidoModel;
import br.ucb.cesbdao.persistencia.dao.AtendidoDAO;
import br.ucb.cesbdao.persistencia.factory.FactoryConnection;
import br.ucb.cesbdao.persistencia.factory.FactoryDAO;
import br.ucb.cesbdao.servicos.Servicos;

public class AtendidoModelImpl implements AtendidoModel{

	private Logger logger = Servicos.carregaLog(AtendidoModelImpl.class);
	@Getter @Setter
	private AtendidoDAO dao;
	
	public AtendidoModelImpl() {
	}
	
	@Override
	public ArrayList<Pessoa> consultaPaciente() {
		try{
			setDao(FactoryDAO.getDaoAtendido(FactoryConnection.getInstance().criaConexao()));
			return getDao().consultaPaciente();
		} catch (ClassNotFoundException | SQLException e) {
			logger.error(e.getMessage());
			e.printStackTrace();
		} finally {
			FactoryConnection.getInstance().closeConexao(getDao().getConexao());
		}
		return null;
	}

	@Override
	public ArrayList<Pessoa> consultaPacienteByNome(String nome) {
		try{
			setDao(FactoryDAO.getDaoAtendido(FactoryConnection.getInstance().criaConexao()));
			return getDao().consultaPacienteByNome(nome);
		} catch (ClassNotFoundException | SQLException e) {
			logger.error(e.getMessage());
			e.printStackTrace();
		} finally {
			FactoryConnection.getInstance().closeConexao(getDao().getConexao());
		}
		return null;
	}
}
